home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / altitude.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  8KB  |  372 lines

  1. /* --------------------------------- altitude.c ----------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* paint the Head Up Display: altitude
  8. */
  9.  
  10. #include "plane.h"
  11.  
  12.  
  13. extern void FAR
  14. show_altitude (HUD *h, OBJECT *p, int sx, int sy, int maxx, int maxy, int orgx,
  15.     int orgy, int ttx, int tty, int tx, int ty, int ss, int shifty,
  16.     int VVD[2])
  17. {
  18.     int    hud, hud1, big, fine, xfine, fa18, f16, f15, fcl, knots, blink;
  19.     int    ether;
  20.     int    x, y, base, ybase, s, x0, y0, dm, dd, i, ex;
  21.     int    res, unit, vtick;
  22.     int    scale_ref, scale_len_l, scale_len_h, savedec;
  23.     long    t, alt;
  24.  
  25.     hud = EX->hud;
  26.     hud1 = EX->hud1;
  27.     fine = hud & HUD_FINE;
  28.     xfine = hud & HUD_XFINE;
  29.     big = hud & HUD_BIG;
  30.     i = hud1 & HUD_TYPES;
  31.     fa18 = i == HUD_FA18;
  32.     f16  = i == HUD_F16;
  33.     f15  = i == HUD_F15;
  34.     fcl  = i == HUD_CLASSIC;
  35.     ether = i == HUD_ETHER;
  36.     knots = hud1 & HUD_KNOTS;
  37.     blink = ((int)st.present)&0x0080;
  38.  
  39.     if (sx < 100) {
  40.         if (xfine)
  41.             fine = 1;
  42.         xfine = 0;
  43.     }
  44.  
  45.     dd = num_size (9L, ss);
  46.  
  47.     alt = p->R[Z];                /* altitude */
  48.     if (knots)
  49.         alt = alt*328/100/VONE;        /* feet */
  50.     else
  51.         alt /= VONE;            /* meters */
  52.  
  53.     gr_color (ST_HFG);
  54.  
  55.     if (fa18 || ether) {
  56.         if (!(EX->hud2 & HUD_ALTITUDE))
  57.             return;
  58.  
  59.         s = (ss*7+3)/6;            /* the large font */
  60.         x0 = num_size (9L, s);
  61.         y0 = 3*dd + 2*x0 + 1;
  62.         if (h->flags & HF_ETHERFRAME) {
  63.             i = maxx;
  64.             ex = ETHERALT;
  65.         } else {
  66.             i = sx;
  67.             ex = F18ALT;
  68.         }
  69.         x = i-tx;
  70.         y = y0 + fmul (i, ex);
  71.         if (x > y)
  72.             x = y;
  73.         x += orgx;
  74.         gr_move (x,     orgy);        /* outline */
  75.         gr_draw (x,     orgy+s+1);
  76.         gr_draw (x-y0,  orgy+s+1);
  77.         gr_draw (x-y0,  orgy);
  78.         gr_draw (x,     orgy);
  79.  
  80.         y = orgy + s;
  81.         i = (int)(labs (alt) % 1000);
  82.         t = alt / 1000;
  83.         if (t == 0) {
  84.             dm = num_size ((long)i, s);
  85.             stroke_num (x-dm, y, (long)i, s, ST_HFG);
  86.         } else {
  87.             x0 = x - 3*dd;
  88.             dm = num_size (t, s);
  89.             stroke_num (x0-dm, y, t, s, ST_HFG);
  90.             y -= (s-ss)/2;        /* center the digits */
  91.             stroke_frac (x0, y, (long)i, 3, 0, ss, ST_HFG);
  92.         }
  93.  
  94.         y = orgy - ss/2;
  95.         t = p->V[Z]*60L;            /* vertical speed */
  96.         if (knots)
  97.             t = t*328/100/VONE;        /* feet */
  98.         else
  99.             t /= VONE;
  100.         t = t/10*10;                /* round to 10s */
  101.         dm = num_size (t, ss);
  102.         stroke_num (x-dm, y, t, ss, ST_HFG);
  103.     } else {
  104.         int        frac;
  105.  
  106.         if (f15) {
  107.             scale_ref = 15;
  108.             scale_len_l = 8;
  109.             scale_len_h = scale_len_l;
  110.         } else if (f16) {
  111.             scale_ref = 40;
  112.             scale_len_l = 8;
  113.             scale_len_h = scale_len_l+1;
  114.         } else {
  115.             scale_ref = 30;
  116.             scale_len_l = EX->tapelen;
  117.             scale_len_h = scale_len_l;
  118.         }
  119.  
  120.         if (f15) {
  121.         if (EX->equip & EQ_GEAR) {
  122.             res   = 20;        /* res*100*VONE is wraparound */
  123.             unit  = 20;        /* tick number multiplier */
  124.             vtick = 5*VONE;        /* v. velocity per tick */
  125.         } else {
  126.             res   = 100;
  127.             unit  = 100;
  128.             vtick = 100*VONE;
  129.         }
  130.         frac = 0;
  131.         } else if (EX->equip & EQ_GEAR) {
  132.         vtick = 10*VONE;
  133.             if (f16) {
  134.             res   = 20;
  135.             unit  = -5;
  136.             frac  = 1;
  137.             } else {
  138.             res   = 10;
  139.             unit  = 100;
  140.             frac  = 0;
  141.             }
  142.         } else {
  143.         res   = 100;
  144.         unit  = 1;
  145.         vtick = 100*VONE;
  146.         frac  = 1;
  147.         }
  148.  
  149.         if (alt >= 0) {
  150.         x0 = (int)(alt % (100L*res));
  151.         ex = (int)(alt/(100L*res));
  152.         } else {
  153.         x0 = 100*res-(int)((-alt) % (100L*res));
  154.         ex = -(int)(-alt/(100L*res) + 1);
  155.         }
  156.         s = x0/res;
  157.         y0 = x0 - s*res;
  158.         ybase = get_center (p, orgy, sy, VVD);
  159.         y0 = ybase + muldiv (y0, sy, scale_ref*res);
  160.  
  161.         base = orgx;
  162.         if (f15)
  163.             base += fmul (sx, F15ALT);
  164.         else if (f16)
  165.             base += fmul (sx, F16ALT);
  166.         else
  167.         base += sx;
  168.  
  169.         dm = (f15||f16) ? 2+2*tx : 2+tx;
  170.  
  171. /* aoa at top of scale
  172. */
  173.         if (f16||f15) {
  174.         t = ANG2DEG00(EX->aoa)/10;
  175.         x = base + (f15 ? -dd : 4*dd);        /* right margin */
  176.         x -= frac_size (t, 0, 1, ss);
  177.         y = muldiv (sy, scale_len_h, scale_ref);
  178.         y += f15 ? -ss/2 : ss;
  179.         stroke_frac (x, ybase-y, t, 0, 1, ss, ST_HFG);
  180.         }
  181.  
  182.         if (!(EX->hud2 & HUD_ALTITUDE))
  183.         return;
  184.  
  185. /* draw scale line.
  186. */
  187.         if (f15) {
  188.         y = muldiv (sy, scale_len_h, scale_ref);
  189.         gr_move (base, ybase - y);        /* top */
  190.         y = muldiv (sy, scale_len_l, scale_ref);
  191.         gr_draw (base, ybase + y);        /* bottom */
  192.         }
  193.  
  194. /* The scale is drawn bottom to top.
  195. */
  196.         savedec = f16 ? stroke_decimal (',') : -1;
  197.         for (i = 1-scale_len_l, s += i; i <= scale_len_h; ++i, ++s) {
  198.         y = y0 - muldiv (sy, i, scale_ref);
  199.         if (f15||f16) {
  200.             if (0 == s%5) {
  201.                 if (unit >= 0)
  202.                     t = (ex*100L + s)*unit;
  203.                 else
  204.                     t = (ex*100L + s)/(-unit);
  205.                 if (big)
  206.                     dm = -num_size (t, ss)-2*tx;
  207.                 stroke_frac (base+dm, y+ss/2, t,
  208.                     (f16 && t >= 0 && t < 1000) ? 3 : 0,
  209.                     frac, ss, ST_HFG);
  210.                 gr_move (base, y);
  211.                 gr_draw (base+2*ttx, y);
  212.             } else {
  213.                 gr_move (base, y);
  214.                 gr_draw (base+1*ttx, y);
  215.             }
  216.         } else if (0 == s%10) {
  217.             gr_move (base, y);
  218.             gr_draw (base+3*ttx, y);
  219.             if (xfine || (i >= -11 && i <= 11)) {
  220.                 t = (ex*10 + s/10)*unit;
  221.                 if (big)
  222.                     dm = -num_size (t, ss)-tx;
  223.                 stroke_num (base+dm, y-2, t, ss, ST_HFG);
  224.             }
  225.         } else if (fine) {
  226.             if (0 == s%2) {
  227.                 gr_move (base, y);
  228.                 gr_draw (base+1*ttx, y);
  229.             }
  230.         } else if (0 == s%5) {
  231.             gr_move (base, y);
  232.             gr_draw (base+2*ttx, y);
  233.         } else if (xfine) {
  234.             gr_move (base, y);
  235.             gr_draw (base+1*ttx, y);
  236.         }
  237.         }
  238.         if (savedec >= 0)
  239.             stroke_decimal (savedec);
  240.  
  241.         if (big)
  242.         base -= 3*tx;
  243.         if (f15) {
  244.             gr_move (base-2*tx, ybase-ty); /* reading mark */
  245.             gr_draw (base,      ybase);
  246.             gr_draw (base-2*tx, ybase+ty);
  247.         } else {
  248.             gr_move (base,      ybase); /* reading mark */
  249.             gr_draw (base-(f16?4:3)*tx, ybase);
  250.         }
  251.         if (fcl) {
  252.  
  253. /* show vertical velocity beside the scale
  254. */
  255.         unit = vtick*5;            /* full scale range */
  256.         s = p->V[Z];            /* vz */
  257.         if (knots)
  258.             s = 3*s + fmul (s, 4601);    /* feet */
  259.         if (s > unit)
  260.             s = unit;
  261.         if (s < -unit)
  262.             s = -unit;
  263.         s = muldiv (sy, s, unit+vtick);
  264.         gr_move (base-tx, ybase);
  265.         gr_draw (base-tx, ybase-s);
  266.  
  267.         y0 = muldiv (sy, vtick, unit+vtick);
  268.         if (s > 0) {
  269.             for (y = 0; y <= s; y += y0) {
  270.                 gr_move (base-tx, ybase-y);
  271.                 gr_draw (base,    ybase-y);
  272.             }
  273.         } else if (s < 0) {
  274.             for (y = 0; y >= s; y -= y0) {
  275.                 gr_move (base-tx, ybase-y);
  276.                 gr_draw (base,    ybase-y);
  277.             }
  278.         }
  279.         }
  280.  
  281.         while (f16) {
  282.         OBJECT    *target;
  283.         LVECT    LL;
  284.         long    range;
  285.         int    closure, i, xx;
  286.  
  287.         y = ybase + muldiv (sy, scale_len_l, scale_ref) + ss/2;
  288.         y0 = orgy+shifty+sy;        /* HUD bottom */
  289.         x = base - 4*dd;
  290.  
  291.         y += ss + ss/2;        /* R data not implemented yet */
  292.         if (y > y0)
  293.             break;
  294.         stroke_str (x, y, "R ", ss, ST_HFG);
  295.  
  296.         y += ss + ss/2;
  297.         if (y > y0)
  298.             break;
  299.         xx = x;
  300.         xx += stroke_str (xx, y, "AL ", ss, ST_HFG);
  301.         savedec = stroke_decimal (',');
  302.         stroke_frac (xx, y, alt/10, 4, 2, ss, ST_HFG);
  303.         stroke_decimal (savedec);
  304.  
  305.         if (F(target = EX->target)) {
  306.             y += 2*ss;
  307.             goto no_target;
  308.         }
  309.         Vsub (LL, p->R, target->R);
  310.         range = lhypot3d (LL);
  311.         if (range)
  312.             closure = (int)(-(LL[X]*(p->V[X] - EX->tspeed[X]) +
  313.                       LL[Y]*(p->V[Y] - EX->tspeed[Y]) +
  314.                       LL[Z]*(p->V[Z] - EX->tspeed[Z])
  315.                      ) / (range*VONE));
  316.         else
  317.             closure = 0;
  318.  
  319.         y += ss;
  320.         if (y > y0)
  321.             break;
  322.         if (knots) {
  323.             if (range < 1853L*VONE) {
  324.                 i = (int)(range/VONE);
  325.                 t = fmul (i, FCON(.0328));    /* ft*100 */
  326.                 stroke_frac (x+2*dd, y, t, 3, 0, ss, ST_HFG);
  327.             } else {
  328.                 t = range*10L/(VONE*1853L);    /* mi/10 */
  329.                 stroke_frac (x, y, t, 4, 1, ss, ST_HFG);
  330.             }
  331.         } else {
  332.             if (range < 1000L*VONE) {
  333.                 t = range/10/VONE;
  334.                 stroke_frac (x+2*dd, y, t, 3, 0, ss, ST_HFG);
  335.             } else {
  336.                 t = range/100/VONE;
  337.                 stroke_frac (x, y, t, 4, 1, ss, ST_HFG);
  338.             }
  339.         }
  340.  
  341.         y += ss;
  342.         if (y > y0)
  343.             break;
  344.         if (knots)
  345.             t = fmul (closure, FCON(3.6/1.853));    /* knots */
  346.         else
  347.             t = fmul (closure, FCON(3.6/2))*2;    /* Km/h */
  348.         stroke_frac (x + (t<0 ? 0 : dd), y, t, 4, 0, ss, ST_HFG);
  349. no_target:
  350.         y += ss;
  351.         if (y > y0)
  352.             break;
  353.         xx = x;
  354.  
  355.         i = EX->ils - 1;
  356.         if (i < 0)
  357.             i = p->home;
  358.         range = ldist3d (p->R, ils[i].R);
  359.         if (knots)
  360.             t = range/VONE/1853;        /* kts */
  361.         else
  362.             t = range/VONE/1000;        /* km */
  363.  
  364.         xx += stroke_frac (xx, y, t, 3, 0, ss, ST_HFG);
  365.         xx += stroke_char (xx, y, '>', ss, ST_HFG);
  366.         stroke_frac (xx, y, (long)i, 2, 0, ss, ST_HFG);
  367.  
  368.         break;
  369.         }
  370.     }
  371. }
  372.